
#ifndef CIRC_BUF_H
#define CIRC_BUF_H

#include "stdbool.h"
#include "stdint.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ELEMENTS_IN_ARRAY(array)        (sizeof(array)/sizeof(array[0]))
#define MB(size)                        ((size) * 1024 * 1024)
#define KB(size)                        ((size) * 1024)
#define ROUND_UP(value, boundary)       ((value) + ((boundary) - (value)) % (boundary))
#define ROUND_DOWN(value, boundary)     ((value) - ((value) % (boundary)))

typedef struct {
    uint32_t head;		
    uint32_t tail;	
    uint32_t size;	
    uint8_t *buf;	
} circ_buf_t;

void		circ_buf_init(circ_buf_t *circ_buf, uint8_t *buffer, uint32_t size);
void		circ_buf_reset(circ_buf_t *circ_buf);
void		circ_buf_push(circ_buf_t *circ_buf, uint8_t data);
uint8_t 	circ_buf_pop(circ_buf_t *circ_buf);
uint32_t	circ_buf_count_used(circ_buf_t *circ_buf);
uint32_t	circ_buf_count_free(circ_buf_t *circ_buf);
uint32_t	circ_buf_read(circ_buf_t *circ_buf, uint8_t *data, uint32_t size);
uint32_t	circ_buf_write(circ_buf_t *circ_buf, const uint8_t *data, uint32_t size);

#ifdef __cplusplus
}
#endif

#endif
